package cn.kevinproject.dingtalk_robot.msg;

import com.dingtalk.api.request.OapiRobotSendRequest;
import lombok.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author kevin lau
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
public class FeedCardMessage extends Message{

    private List<Link> links;


    public FeedCardMessage() {
        this.msgType = "feedCard";
    }

    @Override
    public OapiRobotSendRequest buildRequest() {
        val request = new OapiRobotSendRequest();
        val feedCard =new OapiRobotSendRequest.Feedcard();
        feedCard.setLinks(links.stream().map(t->{
            val link = new OapiRobotSendRequest.Links();
            link.setMessageURL(t.getMessageUrl());
            link.setTitle(t.getTitle());
            link.setPicURL(t.getPicUrl());
            return link;
        }).collect(Collectors.toList()));
        request.setMsgtype(getMsgType());
        request.setFeedCard(feedCard);
        return request;
    }

    @Data
    public static class Link{

        private String title;

        private String messageUrl;

        private String picUrl;
    }
}
